package io.renren.modules.app.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.annotation.LoginUser;
import io.renren.modules.app.entity.ImGroupEntity;
import io.renren.modules.app.entity.ImMomentCommentEntity;
import io.renren.modules.app.entity.ImMomentEntity;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.app.service.ImMomentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2020-05-25 08:44:56
 */
@RestController
@RequestMapping("app/immoment")
public class ImMomentController {
    @Autowired
    private ImMomentService imMomentService;

    /**
     * 新增
     */
    @Login
    @RequestMapping("/create")
    //@RequiresPermissions("generator:imgroup:list")
    public R create(@LoginUser UserEntity user , @RequestBody ImMomentEntity imMoment){

        R r = imMomentService.create(user,imMoment);
        return r;
    }

    /**
     * 朋友圈列表
     * @param user
     * @param imMoment
     * @return
     */

    @Login
    @RequestMapping("/timeline")
    //@RequiresPermissions("generator:imgroup:list")
    public R timeline(@LoginUser UserEntity user , @RequestBody ImMomentEntity imMoment){

        R r = imMomentService.timeline(user,imMoment);
        return r;
    }

    /**
     * 点赞
     * @param user
     * @param imMoment
     * @return
     */

    @Login
    @RequestMapping("/like")
    //@RequiresPermissions("generator:imgroup:list")
    public R like(@LoginUser UserEntity user , @RequestBody ImMomentEntity imMoment){

        R r = imMomentService.like(user,imMoment);
        return r;
    }

    /**
     * 评论
     * @param user
     * @param imMomentComment
     * @return
     */

    @Login
    @RequestMapping("/comment")
    //@RequiresPermissions("generator:imgroup:list")
    public R comment(@LoginUser UserEntity user , @RequestBody ImMomentCommentEntity imMomentComment){

        R r = imMomentService.comment(user,imMomentComment);
        return r;
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:immoment:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = imMomentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:immoment:info")
    public R info(@PathVariable("id") Integer id){
		ImMomentEntity imMoment = imMomentService.getById(id);

        return R.ok().put("imMoment", imMoment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:immoment:save")
    public R save(@RequestBody ImMomentEntity imMoment){
		imMomentService.save(imMoment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:immoment:update")
    public R update(@RequestBody ImMomentEntity imMoment){
		imMomentService.updateById(imMoment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:immoment:delete")
    public R delete(@RequestBody Integer[] ids){
		imMomentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
